unit Class_Link;

interface
uses
  Classes,SysUtils,Uni,UniEngine;

type
  TUnilink=class(TUniEngine)
  public
    LinkIdex: Integer;            
    LinkPath: string;
    LinkName: string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class function  CopyIt(AUnilink:TUnilink):TUnilink;overload;        
    class procedure CopyIt(AUnilink:TUnilink;var Result:TUnilink);overload;       
  end;

implementation

{ TUnilink }
procedure TUnilink.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('LINK_IDEX').Value := LINKIDEX;
        ParamByName('LINK_PATH').Value := LINKPATH;
        ParamByName('LINK_NAME').Value := LINKNAME; 
      end;
      otEdit:
      begin
        ParamByName('LINK_IDEX').Value := LINKIDEX;
        ParamByName('LINK_PATH').Value := LINKPATH;
        ParamByName('LINK_NAME').Value := LINKNAME; 
      end;  
      otDelt:
      begin
        ParamByName('LINK_IDEX').Value := LINKIDEX;
 
      end;  
    end;
  end;
end;

function TUnilink.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_UNILINK',['LINK_IDEX',LINKIDEX],AUniConnection);
end;

function TUnilink.GetNextIdex: Integer;
begin

end;

function TUnilink.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TUnilink.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_UNILINK WHERE   LINK_IDEX=:LINK_IDEX';
end;

function TUnilink.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_UNILINK'
         +'    ( LINK_IDEX, LINK_PATH, LINK_NAME)'
         +'    VALUES'
         +'    (:LINK_IDEX,:LINK_PATH,:LINK_NAME)';
end;

function TUnilink.GetStrsIndex: string;
begin
  Result:=Format('%D',[LINKIDEX]);
end;

function TUnilink.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_UNILINK SET'
         +'    LINK_PATH=:LINK_PATH,'
         +'    LINK_NAME=:LINK_NAME'
         +'    WHERE LINK_IDEX=:LINK_IDEX';
end;

constructor TUnilink.Create;
begin

end;

destructor TUnilink.Destroy;
begin

  inherited;
end;

class function TUnilink.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TUnilink.Create;
  with TUnilink(Result) do
  begin
    LINKIDEX:=AUniQuery.FieldByName('LINK_IDEX').AsInteger;
    LINKPATH:=AUniQuery.FieldByName('LINK_PATH').AsString;
    LINKNAME:=AUniQuery.FieldByName('LINK_NAME').AsString;
  end;  
end;

class function  TUnilink.CopyIt(AUnilink: TUnilink): TUnilink;
begin
  Result:=TUnilink.Create;
  Result.LINKIDEX:=AUnilink.LINKIDEX;
  Result.LINKPATH:=AUnilink.LINKPATH;
  Result.LINKNAME:=AUnilink.LINKNAME;
end;

class procedure TUnilink.CopyIt(AUnilink:TUnilink;var Result:TUnilink);
begin
  if Result=nil then Exit;
  Result.LINKIDEX:=AUnilink.LINKIDEX;
  Result.LINKPATH:=AUnilink.LINKPATH;
  Result.LINKNAME:=AUnilink.LINKNAME;
end;

end.

